package com.sy.mq.controller;

import com.sy.mq.entity.User;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * 消息提供接口
 */
@RestController
@RequestMapping("/send")
public class SendController {


    @Resource
    private RabbitTemplate rabbitTemplate;

    //直连交换机测试
    @RequestMapping("/test")
    public String test() {

        String msg = "hello";
        rabbitTemplate.convertAndSend("myDirectExchange", "my.direct.routing", msg);
        return "success";
    }

    //直连传递对象信息
    @RequestMapping("/obj")
    public String obj(){
        User user = new User(1,"zhangsan",12);
        rabbitTemplate.convertAndSend("myDirectExchange","my.direct.routing",user);
        return "success";
    }


    //扇形交换机测试
    @RequestMapping("/test02")
    public String test02() {
        String msg = "fanout hello";
        rabbitTemplate.convertAndSend("fanoutExchange", null, msg);
        return "success";
    }

    //主题交换机测试
    @RequestMapping("/test03")
    public String test03() {

        String msg = "hello topic--->";
        rabbitTemplate.convertAndSend("myTopicExchange", "topic.01", msg + "topic.01");
        rabbitTemplate.convertAndSend("myTopicExchange", "topic.#", msg + "topic.#");
        return "success";
    }


}
